<?php

namespace IDock\Insurance\ZFIC\Response;

use IDock\Http\Response;
use IDock\Insurance\ZFIC\Response\AllZFICResponse;
use IDock\Printer\ProposalStatusPrinter;
use IDock\Printer\UnderwritingRecallPrinter;
use IDock\Printer\UploadFilePrinter;

class OrderStatusQueryResponse extends AllZFICResponse
{

    public function printerInit(): Response
    {
        $proposalStatusPrinter = new ProposalStatusPrinter();


        $data = $this->getBody();
        $proposalStatusPrinter->messageTip = $data['msg'] ?? '';
        if(($data['state'] ?? '') != '200'){
            $proposalStatusPrinter->messageTip = $data['msg'];
            $this->setError($data['msg']);
            $this->printer = $proposalStatusPrinter;
            return $this;
        }

        $proposalStatusPrinter->ciInquiryNo = $data['data']['policyAppNo'] ?? '';
        $proposalStatusPrinter->biInquiryNo = $data['data']['policyAppNo'] ?? '';
        $status = $data['data']['status'] ?? '';
        if(in_array($status,['1','3','5'])){
            $proposalStatusPrinter->statusCode = 'U1';//核保通过
            $proposalStatusPrinter->status = '核保通过';
        }else if($status == '2' or $status == '0'){
            $proposalStatusPrinter->statusCode = 'U2';//退回修改
            $proposalStatusPrinter->status = '退回修改';
        }else if($status == 'A'){
            $proposalStatusPrinter->statusCode = 'U3';//人工核保
            $proposalStatusPrinter->status = '人工核保';
        }else if($status == '4'){
            $proposalStatusPrinter->statusCode = 'U6';//拒保
            $proposalStatusPrinter->status = '拒保';
        }else if($status == '6'){
            $proposalStatusPrinter->statusCode = 'U5';//已出保单
            $proposalStatusPrinter->status = '已出保单';
        }else if($status == '8' or $status == '9'){
            $proposalStatusPrinter->statusCode = 'U7';//待审核
            $proposalStatusPrinter->status = '待审核';
        }else if($status == '7'){
            $proposalStatusPrinter->statusCode = 'U4';//复核失败
            $proposalStatusPrinter->status = '复核失败';
        }
        if(!empty($proposalStatusPrinter->status)) $proposalStatusPrinter->messageTip = $proposalStatusPrinter->status;
        $this->printer = $proposalStatusPrinter;
        return $this;
    }
}